package com.aaa.doctor.controller.api;

import com.aaa.doctor.feign.system.DeptFeign;
import com.aaa.doctor.feign.system.DictDataFeign;
import com.aaa.doctor.feign.system.RegisteredItemFeign;
import com.aaa.doctor.feign.system.UserFeign;
import com.aaa.entity.Dept;
import com.aaa.entity.DictData;
import com.aaa.entity.RegisteredItem;
import com.aaa.entity.User;
import com.aaa.utils.JwtUtil;
import com.aaa.utils.WebUtil;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author MuChengGuo
 * @date 2023/3/27 14:52
 * Description: TODO
 **/
@Api(tags = "调用系统微服务")
@RestController
@RequestMapping("/doctor/system")
public class SystemApiController {
    @Autowired
    private DictDataFeign dictDataFeign;
    @Autowired
    private DeptFeign deptFeign;
    @Autowired
    private RegisteredItemFeign registeredItemFeign;
    @Autowired
    private UserFeign userFeign;

    @ApiOperation(value = "调用系统管理微服务 - 通过字典类型查询所有字典标签")
    @GetMapping("dictDataByType/{type}")
    public Result<List<DictData>> getDictDataList(
            @ApiParam(value = "字典类型", required = true) @PathVariable String type
    ) {
        List<DictData> byType = dictDataFeign.findByType(type);
        return new Result<>(2000, "成功", byType);
    }

    @ApiOperation(value = "调用系统管理微服务 - 查询所有 部门/科室 信息")
    @GetMapping("deptList")
    public Result<List<Dept>> getDeptList() {
        List<Dept> deptList = deptFeign.getList();
        return new Result(2000, "成功", deptList);
    }

    @ApiOperation(value = "调用系统管理微服务 - 查询 挂号费用 信息")
    @GetMapping("getAllRegisteredItems")
    public Result<List<RegisteredItem>> getAllRegisteredItems() {
        List<RegisteredItem> allRegisteredItems = registeredItemFeign.getAllRegisteredItems();
        return new Result(2000, "成功", allRegisteredItems);
    }

    @ApiOperation(value = "调用系统管理微服务 - 查询当前用户信息")
    @GetMapping("getUser")
    public Result<User> getOneUser() {
        HttpServletRequest request = WebUtil.getRequest();
        String token = request.getHeader("token");
        Map<String, Object> info = JwtUtil.getTokenChaim(token);
        String phoneNumber = (String) info.get("username");
        User byUsername = userFeign.getByUsername(phoneNumber);
        return new Result<User>(2000, "成功", byUsername);
    }

    @ApiOperation(value = "调用系统管理微服务 - 搜索框查询所有医生信息")
    @GetMapping("getListUser")
    public Result<List<User>> getListUser() {
        return new Result<List<User>>(2000, "成功", userFeign.getListUser());
    }

}
